package com.YxyBackMange.Controller.web;

import com.YxyBackMange.Dto.QueryInfo;
import com.YxyBackMange.Entity.Sys.SysUser;
import com.YxyBackMange.Entity.Ware.WareOrderInfo;
import com.YxyBackMange.Mapper.web.WebOrderInfoMapper;
import com.YxyBackMange.Service.web.WebOrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @outhor 路♥克
 * 2017-12-16 4:03
 */
@Controller
@RequestMapping("/OrderInfo")
public class WebOrderInfoController {

    @Autowired
    private WebOrderInfoMapper webOrderInfoMapper;
    @Autowired
    private WebOrderInfoService webOrderInfoService;
    @RequestMapping("/selectOrderInfoByUserId")
    public String selectOrderInfoByUserId(HttpSession session, ModelMap modelMap){
        SysUser user = (SysUser)session.getAttribute("user");
        if(user!=null){
            Map<String,String> map = new HashMap<String, String>();
            map.put("user_id",user.getId().toString());
            QueryInfo queryInfo = new QueryInfo();
            queryInfo.setMap(map);
            List<WareOrderInfo> wareOrderInfos = webOrderInfoMapper.selectQueryInfo(queryInfo);
            modelMap.put("wareOrderInfos",wareOrderInfos);
        }
        return "/web/orderList.jsp";
    }
    @RequestMapping(value = "/insertOrderInfo",method = RequestMethod.GET)
    public @ResponseBody String insertOrderInfo(Double price, HttpSession session){
        SysUser user = (SysUser)session.getAttribute("user");
        WareOrderInfo orderInfo = new WareOrderInfo();
        orderInfo.setOrderMoney(price);
        orderInfo.setUserId(user.getId());
        WareOrderInfo orderInfo1 = webOrderInfoService.insertService(orderInfo);
        if (orderInfo1!=null) {
            return "success";
        }
        return "error";
    }
    @RequestMapping("/deleteOrderInfo")
    public String deleteOrderInfo(Integer id){
        webOrderInfoService.delete(new WareOrderInfo(id));
        return "/OrderInfo/selectOrderInfoByUserId";
    }
}
